package wqh.cfs2000;

import cn.tpson.dti.core.CFSServer;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by devts on 2016/9/23.
 */
@WebServlet(name = "CFS2000Servlet")
public class CFS2000Servlet extends HttpServlet {


    @Override
    public void init(ServletConfig config) throws ServletException {
        super.init(config);

        //spring 管理，便于操作数据库
        ApplicationContext ac = new FileSystemXmlApplicationContext("classpath:/spring/spring-main.xml");
        CFS2000Data cfs2000Data = (CFS2000Data)ac.getBean("cfs2000Data");
        //启动协议解析程序
        int port = Integer.parseInt(config.getInitParameter("port"));
        CFSServer.getInstance().setPort(port);
        CFSServer.getInstance().setProcessor(cfs2000Data);
        CFSServer.getInstance().start();
        System.out.println("协议解析启动#############################################");

    }

    @Override
    public void destroy() {
        super.destroy();
        CFSServer.getInstance().stop();
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
